package StudyCode.summary.mydatetime;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.zone.ZoneOffsetTransition;
import java.time.zone.ZoneRules;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class KnowZoneRules {
	public static void main(String[] args) {
		LocalDateTime now = LocalDateTime.now();
		System.out.println("当前时间: " + now);
		ZoneId fixedZoneId = ZoneId.of("+08:00");
		ZoneId bdDhaka = ZoneId.of("Asia/Dhaka");
		ZoneId usChicago = ZoneId.of("America/Chicago");

		printDetails(fixedZoneId, now);
		printDetails(bdDhaka, now);
		printDetails(usChicago, now);
	}

	private static void printDetails(ZoneId zoneId, LocalDateTime now) {
		System.out.println("Zone ID: " + zoneId.getId());

		ZoneRules rules = zoneId.getRules();
		boolean isFixedOffset = rules.isFixedOffset();
		System.out.println("isFixedOffset(): " + isFixedOffset);

		ZoneOffset offset = rules.getOffset(now);
		System.out.println("Zone offset: " + offset);

		List<ZoneOffsetTransition> transitions = rules.getTransitions();
		System.out.println(transitions);
	}
}
